package org.wxl.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.wxl.comment.R;
import org.wxl.domain.userEntity;
import org.wxl.service.UserService;
import org.wxl.vo.ReqVo.LoginReqVo;
import org.wxl.vo.ReqVo.PasswordChangeReqVo;
import org.wxl.vo.ReqVo.RegisterReqVo;


/**
 * @author 王学良
 */
@Tag(name = "用户管理")
@Slf4j
@RestController
public class UserController {
    @Autowired
    private UserService userService;
    @Operation(summary = "用户登录")
    @PostMapping("user/login")
    public R login( @RequestBody LoginReqVo loginReqVo)
    {
        R token= userService.login(loginReqVo);
        log.info("用户登录");
        return token;
    }
    @Operation(summary = "用户注册")
    @PutMapping("user/register")
    public R register(@RequestBody RegisterReqVo user)
    {
        userService.register(user);
        log.info("用户注册");
        return R.ok().message("注册成功");
    }
    @Operation(summary = "用户更新")
    @PutMapping("/update")
    public R update(@RequestBody userEntity userEntity)
    {
        userService.updateUser(userEntity);
        log.info("用户更新");
        return R.ok().message("更新成功");
    }

    @Operation(summary = "用户删除")
    @GetMapping("/delete/{id}")
    public R delete(@PathVariable String id)
    {
        userService.deleteUserById(id);
        log.info("用户删除");
        return R.ok().message("删除成功");
    }
    @Operation(summary = "用户密码修改")
    @PutMapping("/passwordChange")
    public R passwordChange(@RequestBody PasswordChangeReqVo reqVo)
    {
        String string = userService.passwordChange(reqVo);
        log.info("用户密码修改");
        return R.ok().message(string);
    }
    @Operation(summary = "用户头像修改")
    @PutMapping("/updateAvatar")
    public R updateAvatar(@RequestParam("file") MultipartFile file,
                          @RequestParam("uuid") String uuid) {
            return userService.updateAvatar(file, uuid);
    }

}
